Simply make the following changes to the script:
What used to be:
@files = ("begin.gif","second.gif","third.gif","last.gif");
$con_type = "gif";
Should be replaced with:
@files = ("begin.jpg","second.jpg","third.jpg","last.jpg");
$con_type = "jpeg";
In other words, change the @files variable to
reflect the filenames of the jpg formatted images and
change the $con_type variable to 'jpeg'.